package devices

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"device_srv/deviceclient"

	"github.com/zeromicro/go-zero/core/logx"
)

// @Summary 设备信息展示
// @Description 查询所有设备信息
// @Tags 列表展示
// @Accept json
// @Produce json
// @Param data body types.SendSmsReques true "data"
// @Success 200 {object} types.Response
// @Failure 400 {string} types.Response
// @Failure 500 {string} types.Response
// @Router /devices/devicesList [get]
type DevicesListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDevicesListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DevicesListLogic {
	return &DevicesListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// DevicesList 设备列表展示
func (l *DevicesListLogic) DevicesList(req *types.DevicesListRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.DeviceRpc.DevicesList(l.ctx, &deviceclient.DevicesListRequest{
		DeviceName: req.DeviceName,
		Page:       req.Page,
		PageSize:   req.PageSize,
	})
	if err != nil {
		return respons.Error(400, "查询失败", err.Error()), err
	}
	return respons.Success(list), nil
}
